package www.nfin.ya.service;

import lombok.Data;
import org.yaml.snakeyaml.Yaml;
import www.nfin.ya.utils.SuperOracleUtils;
import www.nfin.ya.utils.impl.OracleTableInfoExtractUtils;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

@Data
public class SystemContextServer {
    public static OracleTableInfoExtractUtils  tableInfoContext;
    public static Properties configProperties = null;
    public static DataSourceConfig dataSourceConfig = new DataSourceConfig();
    static {
        reloadProperties("config.yaml");
        tableInfoContext = new OracleTableInfoExtractUtils();
        tableInfoContext.reload(SuperOracleUtils.setConnection("nfinSIT"));
        SuperOracleUtils.initDefaultConnection();

    }
    private static void reloadProperties(String file){
        SystemContextServer.configProperties = new Properties();
        try {
            InputStream in = SystemContextServer.class.getClassLoader().getResource(file).openStream();
            SystemContextServer.configProperties.load(in);
            in.close();
        } catch (IOException e) {
            System.out.println(file+" 没有找到");
        }
    }
    public static <T> T getYamlProperties(String file, Class<T> t){
        InputStream in = null;
        T user = null;
        try {
            in = SystemContextServer.class.getClassLoader().getResource(file).openStream();
            Yaml yaml = new Yaml();
            user = yaml.loadAs(in, t);
            in.close();
        } catch (IOException e) {
            e.printStackTrace();
        }

        return user;
    }


}
